package com.hzx.demo.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;

import com.hzx.demo.R;
import com.hzx.demo.util.Entry;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;

/**
 * Created by ldkxingzhe on 2016/6/28.
 */
@Entry(desc = "窗口类型的Activity", createTime = "2016-06-28")
@EActivity(R.layout.activity_window_type)
public class WindowTypeActivity extends AppCompatActivity{
    @SuppressWarnings("unused")
    private static final String TAG = "WindowTypeActivity";

    @Click(R.id.btn_show_window)
    protected void showWindow(){
        WindowManager windowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
        WindowManager.LayoutParams params =
                new WindowManager.LayoutParams();
        View rootView = getLayoutInflater().inflate(R.layout.dialog_text, null, false);
        params.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
        params.flags |= WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
        params.flags &= ~WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
        params.alpha = 0.5f;
        windowManager.addView(rootView, params);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
               startActivity(new Intent(WindowTypeActivity.this, WindowTypeActivity_.class));
            }
        }, 5000);
    }
}
